/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package cn.cheln.explorer.ds.util;

import android.content.ContentValues;
import android.provider.MediaStore;

import java.io.File;

import cn.cheln.explorer.beans.FileInfo;
import cn.cheln.explorer.beans.FileUtil;
import cn.cheln.explorer.beans.MusicInfo;
import cn.cheln.explorer.config.Config;
import cn.cheln.explorer.ds.scan.PinyinHelper;
import cn.cheln.support.log.Logs;
import cn.cheln.support.images.FileTypeInfo;
import cn.cheln.support.images.MimeUtil;

/**
 * @author Administrator
 */
public class ContentValuesUtil {

    static ContentValues contentvalues = new ContentValues();

    public static synchronized ContentValues constructContentValues(FileInfo fileinfo, FileTypeInfo typeInfo) {
        contentvalues.clear();
        File file = fileinfo.getFile();
//        Logs.i("", "file.getParent() -- " + file.getAbsolutePath());
        contentvalues.put(MediaStore.Audio.Media.DATA, file.getAbsolutePath());
        contentvalues.put("format", file.isDirectory() ? 12289 : 12288);
        contentvalues.put("sort_key", fileinfo.sortKey==null||fileinfo.sortKey.trim().equals("")?PinyinHelper.transfer(file.getName()):fileinfo.sortKey);
        contentvalues.put(MediaStore.Audio.Media.TITLE, file.getName());
        contentvalues.put(MediaStore.Audio.Media.SIZE, file.length());
        contentvalues.put(MediaStore.Audio.Media.DATE_MODIFIED, file.lastModified() / 1000);
        contentvalues.put(MediaStore.Audio.Media.MIME_TYPE, typeInfo.mime);
        if (fileinfo instanceof MusicInfo) {
            contentvalues.put("album_id", ((MusicInfo) fileinfo).album_id);
            Logs.i("", "------------ aa " + ((MusicInfo) fileinfo).album_id);
            contentvalues.put("album_artist_id", ((MusicInfo) fileinfo).album_artist_id);
        }
        return contentvalues;
    }

    public static synchronized ContentValues constructContentValues(File file, String ext) {

        contentvalues.clear();
        contentvalues.put(MediaStore.Audio.Media.DATA, file.getAbsolutePath());
        contentvalues.put(MediaStore.Audio.Media.TITLE, Config.isLewaRom ? FileUtil.getNameTitle(file.getAbsolutePath()) : file.getName());
        contentvalues.put(MediaStore.Audio.Media.SIZE, file.length());
        contentvalues.put(MediaStore.Audio.Media.DATE_MODIFIED, file.lastModified() / 1000);
        contentvalues.put(MediaStore.Audio.Media.MIME_TYPE, MimeUtil.parseMime(file));
        contentvalues.put("format", file.isDirectory() ? 12289 : 12288);
        contentvalues.put("sort_key", PinyinHelper.transfer(file.getName()));

        return contentvalues;
    }
}
